package pl.sar.auth.server.ejb.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table( name = "PROJECTS" )
public class Project implements Serializable
{

    private static final long serialVersionUID = -1010455548215515863L;

    @Id
    @GeneratedValue( strategy = GenerationType.IDENTITY )
    private long id;

    @Column( name = "name", unique = true, nullable = false )
    private String name;

    @Column( name = "valid" )
    private boolean valid;

    @Column( name = "description" )
    private String description;
    
    @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, mappedBy = "project")
    private List<User> users;

    public Project()
    {
    }

    public long getId()
    {
        return id;
    }

    public void setId( long id )
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName( String name )
    {
        this.name = name;
    }

    public boolean isValid()
    {
        return valid;
    }

    public void setValid( boolean valid )
    {
        this.valid = valid;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription( String description )
    {
        this.description = description;
    }

	public List<User> getUsers() {
		users.size();
		return users;
	}

	public void addUser(User user) {
		if(users == null)
		{
			users = new ArrayList<User>();
		}
		user.setProject(this);
		users.add(user);
	}

}